{% extends "approval/base.html" %}
{% block title %} 申请列表 {% endblock %}
{% block content %}
    <style>
        thead > tr > th {
            white-space: nowrap
        }
    </style>
    <section class="panel panel-default" style="margin: 10px">
        <div class="panel-body">
            <div class="col-lg-12" style="padding: 10px">
                <form class="form-inline" role="search" action="{{ request.path }}" type="get">
                    <input type="hidden" name="g" value="{{ request.GET.g }}" >
                    <div class="form-group">
                        <label class="sr-only" for="search"></label>
                        <input id="search" type="text" class="form-control" name="search" value="{{ request.GET.search }}" placeholder="请输入">
                    </div>
                    {% if not request.GET.g|escape == '2' %}
                    <div class="form-group">
                        <label for="s" class="sr-only" >状态</label>
                        <select id="s" name="s" class="form-control">
                            <option value="">状态</option>
                            {% for s in application_status_choices %}
                                {% if request.GET.s|escape == s.pk|escape %}
                                    <option value="{{ s.pk }}" selected>{{ s.name }}</option>
                                {% else %}
                                    <option value="{{ s.pk }}">{{ s.name }}</option>
                                {% endif %}
                            {% endfor %}
                        </select>
                    </div>
                    {% endif %}
                    <div class="form-group">
                        <label for="t" class="sr-only" >状态</label>
                        <select id="t" name="t" class="form-control">
                            <option value="">类型</option>
                            {% for t in related_application_types %}
                                {% if request.GET.t|escape == t.pk|escape %}
                                    <option value="{{ t.pk }}" selected>{{ t.name }}</option>
                                {% else %}
                                    <option value="{{ t.pk }}">{{ t.name }}</option>
                                {% endif %}
                            {% endfor %}
                        </select>
                    </div>
                <div class="form-group">
                    <button type="submit" class="btn btn-info">搜索</button>
                </div>
                <div class="form-group">
                    <div>总共：{{ data_length }}条 | 合计：{{ total_amount|floatformat:"2"|default_if_none:'0' }} 元</div>
                </div>
                </form>
            </div>
        </div>
    </section>
    {% for row in object_list %}
        <div class="col-lg-3 col-md-6">
            <section class="panel panel-default">
                <div class="panel-heading">
                    <div class="panel-title">
                        <a href="{% url 'approval:application' row.pk %}?s={{ request.GET.s }}&t={{ request.GET.t }}&g={{ request.GET.g }}&search={{ request.GET.search }}&page={{ request.GET.page }}">{{ row.code }} - {{ row.get_status_display }}</a>
                    </div>
                </div>
                <div class="panel-body">
                    <div class="progress">
                        <div class="progress-bar progress-bar-info" role="progressbar" aria-valuenow="{{ row.status_number }}"
                            aria-valuemin="0" aria-valuemax="100" style="width: {{ row.status_number }}%;">
                            <span class="sr-only">{{ row.status_number }}% 完成</span>
                        </div>
                    </div>
                </div>
                <table class="table">
                    <tr><td style="width: 30%">日期</td><td>{{ row.date_info }}</td></tr>
                    <tr><td style="width: 30%">单号</td><td>{{ row.code }}</td></tr>
                    <tr><td style="width: 30%">申请人</td><td>{{ row.created_by.full_name }}</td></tr>
                    <tr><td style="width: 30%">当前状态</td><td>{{ row.get_status_display }}</td></tr>
                    <tr><td style="width: 30%">关联项目</td><td>{{ row.related_project.name }}</td></tr>
                    <tr><td style="width: 30%">报销内容</td><td>{{ row.name }}</td></tr>
                    <tr><td style="width: 30%">报销备注</td><td>{{ row.initial_notes|linebreaks }}</td></tr>
                    <tr><td style="width: 30%">报销金额</td><td><b>{{ row.initial_amount }} 元</b></td></tr>
                    <tr><td style="width: 30%">有无发票</td><td>{{ row.has_invoice|yesno:"有,无" }}</td></tr>
                    <tr><td style="width: 30%">打款方式</td><td>{{ row.get_pay_channel_display|default_if_none:"" }}</td></tr>
                    <tr><td style="width: 30%">附件</td><td>
                        {% for at in row.attachments %}
                            <a href="{{ at.file.url }}" target="_blank">{{ at.file_name }}</a>{% if not forloop.last %}<br>{% endif %}
                        {% endfor %}
                        </td>
                    </tr>
                    {% if row.status > 2 %}
                        <tr class="active">
                            <td style="width: 30%">审批金额</td>
                            <td><b>{{ row.approval_amount }} 元</b></td>
                        </tr>
                        <tr class="active">
                            <td style="width: 30%">审批备注</td>
                            <td>{{ row.approval_notes|default_if_none:'无' }}</td>
                        </tr>
                    {% endif %}
                    <tr><td style="width: 30%">操作</td>
                        <td>
                            <form class="form-horizontal" method="post" action="{% url 'approval:application_submit' row.pk %}?s={{ request.GET.s }}&t={{ request.GET.t }}&g={{ request.GET.g }}&search={{ request.GET.search }}">{% csrf_token %}
                                <input type="hidden" name="status" id="id_status" value="{% if row.status == 1 %}2{% elif row.status == 4 %}6{% endif %}">
                                <a href="{% url 'approval:application' row.pk %}?s={{ request.GET.s }}&t={{ request.GET.t }}&g={{ request.GET.g }}&search={{ request.GET.search }}"><span class="btn btn-info btn-xs">详情</span></a>
                                {% if row.status == 1 or row.status == 5 %}<a href="{% url 'approval:application_change' row.pk  %}?s={{ request.GET.s }}&t={{ request.GET.t }}&g={{ request.GET.g }}&search={{ request.GET.search }}"><span class="btn btn-warning btn-xs">编辑</span></a>{% endif %}
                                {% if row.status == 1 %}<button type="submit" class="btn btn-primary btn-xs">提交</button>{% endif %}
                                {% if row.status == 4 %}<button type="submit" class="btn btn-success btn-xs">确认收款</button>{% endif %}
                                {% if row.status == 2 and request.GET.g|escape == '2' %}<a href="{% url 'approval:application_approve' row.pk %}?s={{ request.GET.s }}&t={{ request.GET.t }}&g={{ request.GET.g }}&search={{ request.GET.search }}"><span class="btn btn-primary btn-xs">审批</span></a>{% endif %}
                            </form>
                        </td>
                    </tr>
                </table>
            </section>
        </div>
    {% endfor %}
    <div class="clearfix"></div>
    <div class="text-right" style="padding-right: 15px">
        {% include 'pagination.html' %}
    </div>
{% endblock %}